import 'package:flutter/material.dart';
import 'package:flutter_base_study/componen/dialog.dart';
import 'package:get/get.dart';

class DialogDemo extends StatefulWidget {
  const DialogDemo({super.key});

  @override
  State<DialogDemo> createState() => _DialogDemoState();
}

class _DialogDemoState extends State<DialogDemo> {
  ///组件化引用 dialog
  void _showMyDialog(String content) {
    showDialog(
        context: context,
        builder: (_) {
          return MyDialog(content1: content);
        });
  }

  ///底部弹框
  void _showBottomDialog() {
    showModalBottomSheet(
        context: context,
        builder: (_) {
          return Container(
            alignment: Alignment.center,
            color: Colors.pink[100],
            child: Text('底部弹框内容'),
            width: 200,
            // padding: EdgeInsets.all(20),
          );
        });
  }

  ///AlertDialog
  void _showAlertDialog() {
    showDialog(
        context: context,
        builder: (_) {
          return AlertDialog(
            title: Text('提示'),
            content: Text('alertdialog content'),
            actions: [
              ElevatedButton(
                  onPressed: () {
                    Navigator.pop(context);
                  },
                  child: Text('确认')),
              ElevatedButton(
                  onPressed: () {
                    Navigator.pop(context);
                  },
                  child: Text('取消')),
            ],
          );
        });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('AlertDialog'),
        centerTitle: true,
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
                onPressed: () {
                  // _showAlertDialog();
                  _showMyDialog('组件化开发dialog,自定义alertdialog');
                },
                child: Text('显示ALertDialog')),
            ElevatedButton(
                onPressed: () {
                  _showBottomDialog();
                },
                child: Text('显示底部弹框')),
            ElevatedButton(
              onPressed: () {
                Get.snackbar(
                  '提示',
                  'Get.snackbar的内容。',
                  icon: Icon(Icons.message),
                  borderRadius: 50,
                );
              },
              child: Text('引用组件化dialog'),
            )
          ],
        ),
      ),
    );
  }
}
